// 清理模块 - 处理初始化清理
import { logDOMInfo, logRemoval, logInitialization } from './logger.js';

// 初始化清理函数
function cleanup(selectors) {
  logInitialization();
  for (const selector of selectors) {
    const elements = document.querySelectorAll(selector);
    elements.forEach(function (element) {
      // 记录初始清理时移除的DOM元素
      logDOMInfo(element, '初始化清理', selector);
      element.remove();
    });
    if (elements.length > 0) {
      logRemoval(selector, elements.length);
    }
  }
}

export function initCleanup(selectors) {
  // DOM加载完成后执行初始清理
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', () => cleanup(selectors));
  } else {
    cleanup(selectors);
  }
}